import { createWebHistory, createRouter } from 'vue-router'
/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/index',
    "meta": {
      title: "首页",
    },
    children: [
      {
        path: '/index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '',
    name: 'productMgmt',
    component: Layout,
    meta: { title: '商品管理', icon: 'dashboard', affix: true },
    children: [
      {
        path: '/productMgmt/productTelemplate',
        component: () => import('@/views/productMgmt/productTelemplate'),
        name: 'ProductTelemplate',
        meta: { title: '商品模板',  affix: true },
      },
      {
        path: 'productMgmt/productTelemplate/add',
        component: () => import('@/views/productMgmt/productTelemplate/add'),
        name: 'ProductTelemplateAdd',
        hidden:false,
      },
      {
        path: 'productMgmt/product',
        component: () => import('@/views/productMgmt/product'),
        name: 'Product',
        meta: { title: '商城商品',  affix: true }
      },
      {
        path: 'productMgmt/productCategory',
        component: () => import('@/views/productMgmt/productCategory'),
        name: 'ProductCategory',
        meta: { title: '商城分类',  affix: true }
      },
      {
        path: 'productMgmt/stock',
        component: () => import('@/views/productMgmt/stock'),
        name: 'Stock',
        meta: { title: '库存管理',  affix: true }
      },
      {
        path: 'productMgmt/stockLog',
        component: () => import('@/views/productMgmt/stockLog'),
        name: 'StockLog',
        meta: { title: '库存日志',  affix: true }
      },
       
    ]
  },
  {
    path: '/orderMgmt',
    component: Layout,
    name: 'OrderMgmt',
    meta: { title: '订单管理', icon: 'dashboard', affix: true },
    children: [
      {
        path: '/orderMgmt/order',
        component: () => import('@/views/orderMgmt/order'),
        name: 'OrderMgmtOrder',
        meta: { title: '待付款',  affix: true }
      },
      // {
      //   path: 'orderMgmt/order',
      //   component: () => import('@/views/orderMgmt/order'),
      //   name: 'ProductTelemplate',
      //   meta: { title: '待付款',  affix: true }
      // },
    ]
  },
]
export const dynamicRoutes = [
]

// 动态路由，基于用户权限动态去加载
export const allPagesRoutes = [

    // {
    //   "id": 1,
    //   "kind": 1,
    //   "menuType": 2,
    //   "title": "首页",
    //   "meta": {
    //     title: "首页",
    //   },
    //   "menuKey": "index",
    //   "menuDesc": null,
    //   "menuUrl": null,
    //   "path": "/index",
    //   "menuIcon": null,
    //   "parentId": 0,
    //   "sortNum": 10,
    //   "codeNo": null,
    //   "status": 1,
    //   "isCharge": 0,
    //   "parent": null,
    //   "children": [],
    //   "parentName": null,
    //   "component": Layout,
    // },
    {
      "id": 47,
      "kind": 1,
      "menuType": 1,
      "title": "会员管理",
      "meta": {
        title: "会员管理",
      },
      "menuKey": "member",
      "menuDesc": null,
      "menuUrl": null,
      "path": null,
      "menuIcon": "icon-huiyuanguanli",
      "parentId": 0,
      "sortNum": 10,
      "codeNo": null,
      "status": 1,
      "isCharge": 0,
      "parent": null,
      "component": Layout,
      "redirect": "/members",
      "children": [
        {
          "id": 48,
          "kind": 1,
          "menuType": 2,
          "title": "会员列表",
          "meta": {
            title: "会员列表",
          },
          "menuKey": "member",
          "menuDesc": null,
          "menuUrl": "/member/getList",
          "path": "/members",
          "menuIcon": null,
          "parentId": 47,
          "sortNum": 10,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/members'),
        }
      ],
      "parentName": null
    },
    {
      "id": 50,
      "kind": 1,
      "menuType": 1,
      "title": "合同管理",
      "meta": {
        title: "合同管理",
      },
      "menuKey": "sige",
      "menuDesc": null,
      "menuUrl": null,
      "path": null,
      "menuIcon": "icon-danjuguanli2",
      "parentId": 0,
      "sortNum": 30,
      "codeNo": null,
      "status": 1,
      "isCharge": 0,
      "parent": null,
      "component": Layout,
      "redirect": "/contracts",
      "children": [
        {
          "id": 52,
          "kind": 1,
          "menuType": 2,
          "title": "合同列表",
          "meta": {
            title: "合同列表",
          },
          "menuKey": "sige",
          "menuDesc": null,
          "menuUrl": "/sige/getList",
          "path": "/contracts",
          "menuIcon": "icon-caidanguanli4",
          "parentId": 50,
          "sortNum": 55,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/contracts'),
        }
      ],
      "parentName": null
    },
    {
      "id": 49,
      "kind": 1,
      "menuType": 1,
      "title": "单据管理",
      "meta": {
        title: "单据管理",
      },
      "menuKey": "bill",
      "menuDesc": null,
      "menuUrl": null,
      "path": null,
      "menuIcon": "icon-danjuguanli",
      "parentId": 0,
      "sortNum": 60,
      "codeNo": null,
      "status": 1,
      "isCharge": 0,
      "parent": null,
      "component": Layout,
      "redirect": "/wxBill",
      "children": [
        {
          "id": 51,
          "kind": 1,
          "menuType": 2,
          "title": "微信账单",
          "meta": {
            title: "微信账单",
          },
          "menuKey": "wxBill",
          "menuDesc": null,
          "menuUrl": "/wxBill/getList",
          "path": "/wxBill",
          "menuIcon": "icon-caidanguanli5",
          "parentId": 49,
          "sortNum": 10,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/wxBill'),
        }
      ],
      "parentName": null
    },
    {
      "id": 53,
      "kind": 1,
      "menuType": 1,
      "title": "投诉建议",
      "meta": {
        title: "投诉建议",
      },
      "menuKey": null,
      "menuDesc": null,
      "menuUrl": null,
      "path": null,
      "menuIcon": "icon-taocanguanli",
      "parentId": 0,
      "sortNum": 60,
      "codeNo": null,
      "status": 1,
      "isCharge": 0,
      "parent": null,
      "component": Layout,
      "redirect": "/complaints",
      "children": [
        {
          "id": 54,
          "kind": 1,
          "menuType": 2,
          "title": "投诉建议",
          "meta": {
            title: "投诉建议",
          },
          "menuKey": null,
          "menuDesc": null,
          "menuUrl": "/complaint/getList",
          "path": "/complaints",
          "menuIcon": null,
          "parentId": 53,
          "sortNum": 55,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/complaints'),
        }
      ],
      "parentName": null
    },
    {
      "id": 6,
      "kind": 1,
      "menuType": 1,
      "title": "组织架构",
      "meta": {
        title: "组织架构",
      },
      "menuKey": "renshi",
      "menuDesc": null,
      "menuUrl": null,
      "path": "",
      "menuIcon": "icon-bumenguanli1",
      "parentId": 0,
      "sortNum": 90,
      "codeNo": null,
      "status": 1,
      "isCharge": 0,
      "parent": null,
      "component": Layout,
      "redirect": "/depts",
      "children": [
        {
          "id": 38,
          "kind": 1,
          "menuType": 2,
          "title": "部门管理",
          "meta": {
            title: "部门管理",
          },
          "menuKey": "depts",
          "menuDesc": null,
          "menuUrl": null,
          "path": "/depts",
          "menuIcon": null,
          "parentId": 6,
          "sortNum": 9,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/depts'),
        },
        {
          "id": 7,
          "kind": 1,
          "menuType": 2,
          "title": "员工列表",
          "meta": {
            title: "员工列表",
          },
          "menuKey": "users",
          "menuDesc": null,
          "menuUrl": null,
          "path": "/users",
          "menuIcon": null,
          "parentId": 6,
          "sortNum": 20,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/users'),
        }
      ],
      "parentName": null
    },
    {
      "id": 2,
      "kind": 1,
      "menuType": 1,
      "title": "系统设置",
      "meta": {
        title: "系统设置",
      },
      "menuKey": "system",
      "menuDesc": null,
      "menuUrl": null,
      "path": "",
      "menuIcon": "icon-xitongshezhi",
      "parentId": 0,
      "sortNum": 99,
      "codeNo": null,
      "status": 1,
      "isCharge": 0,
      "parent": null,
      "component": Layout,
      "redirect": "/roles",
      "children": [
        {
          "id": 4,
          "kind": 1,
          "menuType": 2,
          "title": "角色管理",
          "meta": {
            title: "角色管理",
          },
          "menuKey": "roles",
          "menuDesc": null,
          "menuUrl": null,
          "path": "/roles",
          "menuIcon": null,
          "parentId": 2,
          "sortNum": 10,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/roles'),
        },
        {
          "id": 5,
          "kind": 1,
          "menuType": 2,
          "title": "菜单管理",
          "meta": {
            title: "菜单管理",
          },
          "menuKey": "menus",
          "menuDesc": null,
          "menuUrl": null,
          "path": "/menus",
          "menuIcon": null,
          "parentId": 2,
          "sortNum": 20,
          "codeNo": null,
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/menus'),
        },
        {
          "id": 43,
          "kind": 1,
          "menuType": 2,
          "title": "费用配置",
          "meta": {
            title: "费用配置",
          },
          "menuKey": "sysCode",
          "menuDesc": null,
          "menuUrl": null,
          "path": "/sysConfig",
          "menuIcon": null,
          "parentId": 2,
          "sortNum": 55,
          "codeNo": "60",
          "status": 1,
          "isCharge": 0,
          "parent": null,
          "children": null,
          "parentName": null,
          "component": () => import('@/views/sysConfig'),
        }
      ],
      "parentName": null
    }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    }
    return { top: 0 }
  },
});

export default router;
